//
//  ViewFactory.m
//  Architect
//
//  Created by 张伯林 on 2018/1/30.
//  Copyright © 2018年 张伯林. All rights reserved.
//

#import "ViewFactory.h"
#import "ViewFactoryXmlParser.h"
@interface ViewFactory()
@property(nonatomic)NSMutableDictionary *dic;
@end
@implementation ViewFactory
static ViewFactory *instance = nil;
+(instancetype)shareInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[ViewFactory alloc]init];
    });
    return instance;
}
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    if (instance == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            instance = [super allocWithZone:zone];
        });
    }
    return instance;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        ViewFactoryXmlParser *parser = [[ViewFactoryXmlParser alloc]init];
        _dic = [parser parser];
    }
    return self;
}
//根据条件创建视图控制器
-(id<IProductProtocol>)createProduct:(NSString *)chose{
    if (chose.length > 0) {
        NSString *string = [_dic objectForKey:chose];
        if (string.length > 0) {
            return [[NSClassFromString(string) alloc] init];
        }
    }
    return nil;
}
@end
